package com.yanqu.road.server.cmd.activity.dafuweng.zaoyao;

import com.yanqu.road.entity.activity.dafuweng.DFWConfig;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DA_FU_WENG_HANDLE_ZAO_YAO_EVENT, desc = "处理造谣事件")
public class DaFuWengHandleZaoYaoEventCmd extends AbstractCommand {

    private String unionUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.HandleRumorMakingEventReqMsg reqMsg = MonopolyProto.HandleRumorMakingEventReqMsg.parseFrom(packet.getBytes());
        unionUid = reqMsg.getUnionUid();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
        if (dfwConfig == null || !ActivityMgr.activityInTime(dfwConfig.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_DFW_NO_IN_TIME;
            return;
        }

        ret = DaFuWengMgr.zaoYaoEvent(player, unionUid);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            MonopolyProto.HandleRumorMakingEventRespMsg.Builder builder = MonopolyProto.HandleRumorMakingEventRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_HANDLE_ZAO_YAO_EVENT, builder);
        }
    }
}
